<div id="titulos" align="center"><h1>ANALISIS PRESUPUESTARIO</h1></div><br>
<div id="cajaprincipalproyecto" align="center">

    <?php
    foreach ($listafondos as $fond):
        $listaval = Doctrine::getTable('valor')->createQuery('v')
                ->where('v.id_fo = ?', $fond->getIdFo())
                ->execute();
        $s = 0;
        foreach ($listaval as $va):
            $s = $s + $va->getVal();
        endforeach;
        if ($s == 0) {
            $this->getUser()->setFlash('error', 'No se puede crear el Analisis Presupuestario, porque no existen valores ingresados!');
            $this->redirect('reportes/index?id_pro=' . $idpro);
        }
    endforeach;
    ?>
    <div align="center" id="cajaanalisisindex"><br>
        <table border="1" id="contextual" class="table" align="center" name="campo">
            <tr id="filascolor" align="center">
                <td>RUBROS</td>
                <?php foreach ($listafondos as $fond) { ?>
                    <td>VALORES &nbsp <?php echo $fond->getSiglasInst() ?></td>
                    <td>% FINANCIAMIENTO &nbsp <?php echo $fond->getSiglasInst() ?></td>
                <?php } ?>
            </tr>
            <?php
            $techospro = Doctrine::getTable('techos')->createQuery('t')
                    ->where('t.id_pro = ?', $idpro)
                    ->execute();
            $total1 = 0;
            $total2 = 0;
            $ptotal1 = 0;
            $ptotal2 = 0;
            foreach ($techospro as $te):
                ?>
                <tr  align="center">
                    <td align="justify"><?php echo $te->getNombre() ?></td>
                    <?php
                    $ba = 0;
                    foreach ($listafondos as $fond) :
                        $ba++;
                        $totalfondo = 0;
                        $totalfondo = Doctrine::getTable('valor')->createQuery('v')
                                ->where('v.id_fo = ?', $fond->getIdFo())
                                ->execute();
                        foreach ($totalfondo as $tf):
                            $totalfondo = $totalfondo + $tf->getVal();
                        endforeach;
                        $totaltecho = 0;
                        $descripciones = Doctrine::getTable('descripciongeneral')->createQuery('d')
                                ->where('d.id_tp = ?', $te->getIdTp())
                                ->execute();
                        foreach ($descripciones as $de):
                            $valores = Doctrine::getTable('valor')->createQuery('v')
                                    ->where('v.id_dg = ?', $de->getIdDg())
                                    ->andwhere('v.id_fo = ?', $fond->getIdFo())
                                    ->execute();
                            foreach ($valores as $va):
                                $totaltecho = $totaltecho + $va->getVal();
                            endforeach;
                        endforeach;
                        ?>

                        <td><?php echo $totaltecho ?></td>
                        <td><?php echo round((100 * $totaltecho) / $totalfondo, 2) ?>%</td>                    

                        <?php
                        if ($ba == 1) {
                            $total1 = $total1 + $totaltecho;
                            $ptotal1 = $ptotal1 + round((100 * $totaltecho) / $totalfondo, 2);
                        } else if ($ba == 2) {
                            $total2 = $total2 + $totaltecho;
                            $ptotal2 = $ptotal2 + round((100 * $totaltecho) / $totalfondo, 2);
                        }
                    endforeach;


                endforeach;
                ?>
            </tr>      
            <tr align="center">
                <td id="filascolor">MONTO DEL APORTE </td>
                <?php if ($ba == 1) { ?>
                    <td><?php echo $total1 ?></td>
                    <td></td>
                <?php } else { ?>
                    <td><?php echo $total2 ?></td>
                    <td><?php echo $ptotal2 ?></td>
                <?php }
                ?>
            </tr>



        </table>
    </div><br></br>    
    <div align="center">
        <a href="<?php echo url_for('Reportes/Analisis2'); ?>"><button class="buttonmediumauto button-green" ><span><div id="imagenes" valign="middle"><div  align="center" class="spritesexportresmall" id="exportresmall_jpg" align="center"></div></div><div id="textobutton2">Exportar a Excel</div></span></button></a>
        <a href="<?php echo url_for('Reportes/Analisis2L'); ?>"><button class="buttonmediumauto button-green" ><span><div id="imagenes" valign="middle"><div  align="center" class="spritesexportresmall" id="exportresmall_jpg" align="center"></div></div><div id="textobutton2">Exportar a Open Calc</div></span></button></a>
        <a href="<?php echo url_for('Reportes/ExportarAnalisisPDF'); ?>"><button class="buttonmediumauto button-green" ><span><div id="imagenes" valign="middle"><div  align="center" class="spritesexportresmall" id="exportresmall_jpg" align="center"></div></div><div id="textobutton2">Exportar A PDF</div></span></button></a>
        <a href="<?php echo url_for('Reportes/index?id_pro=' . $idpro) ?>"><button class="buttonmediumauto button-green"><span><div id="imagenes" valign="middle"><div align="center"  class="spritesatrasmall" id="atrasmall_jpg" align="center"></div></div><div id="textobutton2">Regresar a Menu Reportes</div></span></button></a><br><br>

    </div><br><br>



    <br><br>
    <div align="center">
        <a href="<?php echo url_for('Reportes/index?id_pro=' . $idpro) ?>"><button class="buttonmediumauto button-green"><span><div id="imagenes" valign="middle"><div align="center"  class="spritesatrasmall" id="atrasmall_jpg" align="center"></div></div><div id="textobutton2">Regresar a Menu Reportes</div></span></button></a><br><br>

    </div>



</div>
<div id="ajaxmodal" style="display: none;">
    <div id="imageajax" style="display: none;">
        <b>Su Reporte esta siendo Generado, Por favor Espere unos minutos</b><br><br>
        </bt>        <?php echo image_tag('ajax-loader.gif'); ?>
    </div>    
</div>